package concurrency.basicthreading.demo;

public class Demo12Joiner extends Thread {
	private Demo12Sleeper sleeper = null;
	
	public Demo12Joiner (String name, Demo12Sleeper sleeper) {
		super(name);
		this.sleeper = sleeper;
		start();
	}
	@Override
	public void run() {
		try {
			/*
			 * Joiner线程调用Sleeper线程的join方法, 结果是Joiner线程等待Sleeper线程结束后继续运行。(也就是说Joiner线程被挂起，
			 * 直到目标线程Sleeper结束才恢复。即Sleeper.isAlive()返回为假）
			 *
			 * 我们可以再join方法里带一个超时参数如下。如果目标线程sleeper线程在1秒时间段内还没有结束的话。join方法总能返回。
			 * this.sleeper.join(10000);
			*/
			this.sleeper.join();
		} catch (InterruptedException e) {
			System.out.println("Interrupted");
		}
		
		System.out.println(getName() + " join completed");
	}

}
